package org.javaforever.gatescore.reports.verb;

import java.util.ArrayList;
import java.util.List;

import org.javaforever.gatescore.core.FrontCodeBlock;
import org.javaforever.gatescore.core.FrontDomain;
import org.javaforever.gatescore.core.FrontDropdown;
import org.javaforever.gatescore.core.FrontMethod;
import org.javaforever.gatescore.core.FrontVerb;
import org.javaforever.gatescore.core.Statement;
import org.javaforever.gatescore.core.Writeable;
import org.javaforever.gatescore.core.WriteableUtil;
import org.javaforever.gatescore.utils.StringUtil;
import org.javaforever.gatescore.verb.ListActive;

public class Translate extends FrontVerb{
	private static final long serialVersionUID = 1L;
	protected FrontDomain domain;

	public Translate(FrontDomain domain) {
		super();
		this.setVerbName("Translate");
		this.setLabel("翻译");
		this.domain = domain;
	}

	@Override
	public FrontMethod generateControllerMethod() throws Exception {
		FrontMethod method = new FrontMethod();
		method.setStandardName("translate");
		List<Writeable> sList = new ArrayList<Writeable>();
		sList.add(new Statement(1000L,0,"translate"+this.domain.getCapFirstDomainName()+"(value) {"));
		sList.add(new Statement(2000L,1,"if (isBlank(value)) return ''"));
		sList.add(new Statement(3000L,1,"for (var i = 0; i < this.active"+this.domain.getCapFirstPlural()+".length; i++) {"));
		sList.add(new Statement(4000L,2,"if (this.active"+this.domain.getCapFirstPlural()+"[i]."+this.domain.getDomainId().getLowerFirstFieldName()+" === value) {"));
		sList.add(new Statement(5000L,3,"return this.active"+this.domain.getCapFirstPlural()+"[i]."+this.domain.getDomainName().getLowerFirstFieldName()));
		sList.add(new Statement(6000L,2,"}"));
		sList.add(new Statement(7000L,1,"}"));
		sList.add(new Statement(8000L,1,"return ''"));
		sList.add(new Statement(9000L,0,"},"));

		method.setMethodStatementList(WriteableUtil.merge(sList));
		return method;
	}

	@Override
	public FrontMethod generateApiMethod() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public FrontCodeBlock generateRouteBlockBlock() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public FrontMethod generateControllerMethod(String indexSuffix) throws Exception {
		return generateControllerMethod();
	}
}
